{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import random\n",
    "import cv2\n",
    "\n",
    "def rotate_image(image_path, output_path, degrees):\n",
    "    image = cv2.imread(image_path)\n",
    "    height, width = image.shape[:2]\n",
    "    rotation_matrix = cv2.getRotationMatrix2D((width / 2, height / 2), degrees, 1)\n",
    "    rotated_image = cv2.warpAffine(image, rotation_matrix, (width, height))\n",
    "    cv2.imwrite(output_path, rotated_image)\n",
    "\n",
    "def rotate_images_in_folder(input_folder, output_folder, degrees_list):\n",
    "    if not os.path.exists(output_folder):\n",
    "        os.makedirs(output_folder)\n",
    "\n",
    "    image_files = os.listdir(input_folder)\n",
    "    for file_name in image_files:\n",
    "        image_path = os.path.join(input_folder, file_name)\n",
    "        output_path = os.path.join(output_folder, \"rot_\" + file_name)\n",
    "        degrees = random.choice(degrees_list)  # Random rotation angle within list\n",
    "        rotate_image(image_path, output_path, degrees)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Example usage\n",
    "input_folder = '/home/$USER/test_images_split/front'\n",
    "output_folder = '/home/$USER/test_images_split/rotated'\n",
    "degrees_list = [45, 90, 135, 180, 225, 270, 315]  # Range of degrees for random rotation\n",
    "\n",
    "rotate_images_in_folder(input_folder, output_folder, degrees_list)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "gauge_reading",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.16"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
